﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using DreamBuilder.UI.UserControls.DataAccess.Services;
using System.Data;
using System.Data.OracleClient;
using DreamBuilder.Core.DAO;


namespace DreamBuilder.UI.UserControls.DataAccess.Components
{
    public class OracleRefListDAL : RefListDAL
    {
        public override string RefListDBHelperString { get; set; }
        public override DataTable SelectListPaged(string select, string from, string where, string orderBy, string ascOrDesc, int intPageIndex, int intPageSize, out int recordCount)
        {
            OracleParameter v_cur = new OracleParameter("v_cur", OracleType.Cursor);
            v_cur.Direction = ParameterDirection.Output;

            OracleParameter p_recordCount = new OracleParameter("RecordCount", OracleType.Int32);
            p_recordCount.Direction = ParameterDirection.Output;

            OracleParameter p_pageIndex = new OracleParameter("PageIndex", OracleType.Int32);
            p_pageIndex.Value = intPageIndex;
            p_pageIndex.Direction = ParameterDirection.InputOutput;

            OracleParameter p_pageSize = new OracleParameter("PageSize", OracleType.Int32);
            p_pageSize.Value = intPageSize;
            p_pageSize.Direction = ParameterDirection.InputOutput;

            DbParameter[] parameters = new DbParameter[]
            {
                new  OracleParameter ("SelectStatement",select),
                new  OracleParameter ("FromStatement",from),
                new  OracleParameter ("WhereStatement",where),
                new  OracleParameter ("OrderByExpression",orderBy),
                new  OracleParameter ("AscOrDesc",ascOrDesc),
                p_pageIndex,
                p_pageSize,
                p_recordCount,
                v_cur

            };
            if (!string.IsNullOrEmpty(RefListDBHelperString))
            {
                IDBHelper dbHelper = DBHelperFactory.CreateInstance(RefListDBHelperString);
                DataTable dtInfo = dbHelper.RunProcedureDataTable("proc_qurey", parameters);
                recordCount = Convert.ToInt32(p_recordCount.Value);
                return dtInfo;
            }
            else
            {
                recordCount = 0;
                return null;
            }
        }
    }
}
